package com.snail.controller;

import com.snail.common.PluginRegistry;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value = "/plugin")
public class PluginAdminController {

    @Autowired
    private PluginRegistry pluginRegistry;

    @RequestMapping("/load")
    public String loadPlugin() {
        String path = "D:\\luolf\\personal\\git_home\\snail-demo\\DynamicModel-demo\\target\\DynamicModel-demo-1.0-SNAPSHOT.jar";
        try {
            pluginRegistry.loadPlugin(path);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return "插件加载成功";
    }

    @RequestMapping("/unload")
    public String unloadPlugin() {
        String path = "D:\\luolf\\personal\\git_home\\snail-demo\\DynamicModel-demo\\target\\DynamicModel-demo-1.0-SNAPSHOT.jar";
        pluginRegistry.unregisterPlugin(path);
        return "插件卸载成功";
    }
}
